﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FuncAdapterFactory.cs" company="">
//   
// </copyright>
// <summary>
//   The func adapter factory.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Adapters
{
    using System;

    /// <summary>
    /// The func adapter factory.
    /// </summary>
    /// <typeparam name="T1">
    /// </typeparam>
    /// <typeparam name="T2">
    /// </typeparam>
    public class FuncAdapterFactory<T1, T2> : IAdapterFactory
    {
        #region Fields

        /// <summary>
        ///   The _create adapter func.
        /// </summary>
        private readonly Func<T1, T2> _createAdapterFunc;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="FuncAdapterFactory{T1,T2}"/> class.
        /// </summary>
        /// <param name="createAdapterFunc">
        /// The create adapter func. 
        /// </param>
        public FuncAdapterFactory(Func<T1, T2> createAdapterFunc)
        {
            this._createAdapterFunc = createAdapterFunc;
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///   Gets the type 1.
        /// </summary>
        public Type Type1
        {
            get
            {
                return typeof(T1);
            }
        }

        /// <summary>
        ///   Gets the type 2.
        /// </summary>
        public Type Type2
        {
            get
            {
                return typeof(T2);
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The create adapter.
        /// </summary>
        /// <param name="obj">
        /// The obj. 
        /// </param>
        /// <returns>
        /// The <see cref="object"/> . 
        /// </returns>
        public object CreateAdapter(object obj)
        {
            return this._createAdapterFunc((T1)obj);
        }

        #endregion
    }
}